package com.blogSystem.article.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.blogSystem.article.client.BaseClient;
import com.blogSystem.article.client.UserClient;
import com.blogSystem.article.dao.ThumbsMapper;
import com.blogSystem.article.pojo.Article;
import com.blogSystem.article.pojo.Thumbs;
import com.blogSystem.article.pojo.User;
import com.blogSystem.article.service.ArticleService;
import com.blogSystem.article.service.ThumbsSerivlce;
import com.blogSystem.article.util.TimeDifference;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import util.JwtUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/article")

public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private ThumbsSerivlce thumbsSerivlce;

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private BaseClient baseClient;

    @Autowired
    private UserClient userClient;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result getList(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size) {
        Page<Article> articles = articleService.findReviewed(page, size);


        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (articles != null && articles.getSize()!=0) {
            List<Article> articleList = articles.getContent();

            if (token == null || "".equals(token)) {

                List<Map> maps = new ArrayList<Map>();

                for (Article article : articleList) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();

                    map.put("article", article);
                    map.put("thumbs", "null");
                    maps.add(map);
                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);

            } else {
                String user_id = claims.getId();
                List<Map> maps = new ArrayList<Map>();
                for (Article article : articles) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    if (thumbsSerivlce.findThumbs(article.get_id(), user_id) == null) {
                      String json=userClient.getUserById(article.getAuthor());
                      User user=JSON.parseObject(json,User.class);
                      article.setAuthorName(user.getUsername());
                        map.put("article", article);
                        map.put("thumbs", "no");
                        maps.add(map);

                    } else {
                      String json=userClient.getUserById(article.getAuthor());
                      User user=JSON.parseObject(json,User.class);
                      article.setAuthorName(user.getUsername());
                        map.put("article", article);
                        map.put("thumbs", "yes");
                        maps.add(map);
                    }

                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);


            }
        }




        return new Result(true, StatusCode.ERROR, "无记录！");
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result addArticle(@RequestBody String json) {

        String token = (String) request.getAttribute("token");

            Claims claims=jwtUtil.parseJWT(token);
            String user_id = claims.getId();
            String userName=claims.getSubject();
      System.out.println(json);
      JSONObject jsonObject=JSON.parseObject(json);
            Article article=  JSON.parseObject(json,Article.class);
            article.setAuthor(user_id);


            HttpSession session=request.getSession();
            if(session.getAttribute("cover")==null){
              return new Result(false, StatusCode.ERROR, "未上传封面！");
            }
            String cover= (String) session.getAttribute("cover");
            article.setCover(cover);
            articleService.save(article);
            return new Result(true, StatusCode.OK, "添加成功！");

    }

    @RequestMapping(value = "/find_by_title", method = RequestMethod.POST)
    public Result findByTitle(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size, String title) {
        Page<Article> articles = articleService.findByTitle(title, page, size);
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (articles != null && articles.getSize()!=0) {
            List<Article> articleList = articles.getContent();

            if (token == null || "".equals(token)) {

                List<Map> maps = new ArrayList<Map>();

                for (Article article : articleList) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("article", article);
                    map.put("thumbs", "null");
                    maps.add(map);
                }

                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);

            } else {
                String user_id = claims.getId();
                List<Map> maps = new ArrayList<Map>();
                for (Article article : articles) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    if (thumbsSerivlce.findThumbs(article.get_id(), user_id) == null) {
                        map.put("article", article);
                        map.put("thumbs", "no");
                        maps.add(map);

                    } else {
                        map.put("article", article);
                        map.put("thumbs", "yes");
                        maps.add(map);
                    }

                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);


            }
        }




        return new Result(true, StatusCode.ERROR, "无记录！");
    }

    @RequestMapping(value = "/find_by_label", method = RequestMethod.POST)
    public Result findByLabel(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size, String label) {
        Page<Article> articles = articleService.findByLabelAndPage(label, page, size);
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (articles != null && articles.getSize()!=0) {
            List<Article> articleList = articles.getContent();

            if (token == null || "".equals(token)) {

                List<Map> maps = new ArrayList<Map>();

                for (Article article : articleList) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("article", article);
                    map.put("thumbs", "null");
                    maps.add(map);
                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);

            } else {
                String user_id = claims.getId();

                List<Map> maps = new ArrayList<Map>();
                for (Article article : articles) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    if (thumbsSerivlce.findThumbs(article.get_id(), user_id) == null) {
                        map.put("article", article);
                        map.put("thumbs", "no");
                        maps.add(map);

                    } else {
                        map.put("article", article);
                        map.put("thumbs", "yes");
                        maps.add(map);
                    }

                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);


            }
        }




        return new Result(true, StatusCode.ERROR, "无记录！");
    }

    @RequestMapping(value = "/find_by_author", method = RequestMethod.POST)
    public Result findByAuthor(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size, String author) {
      //String json= userClient.getUserById(author);
      /*if (json==null){
        return new Result(false, StatusCode.ERROR, "查询失败");

      }
      User user=JSON.parseObject(json,User.class);*/
        Page<Article> articles = articleService.findByAuthorAndPage(author, page, size);
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (articles != null && articles.getSize()!=0) {
            List<Article> articleList = articles.getContent();

            if (token == null || "".equals(token)) {

                List<Map> maps = new ArrayList<Map>();

                for (Article article : articleList) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("article", article);
                    map.put("thumbs", "null");
                    maps.add(map);
                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);

            } else {
                String user_id = claims.getId();

                List<Map> maps = new ArrayList<Map>();
                for (Article article : articles) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    if (thumbsSerivlce.findThumbs(article.get_id(), user_id) == null) {
                        map.put("article", article);
                        map.put("thumbs", "no");
                        maps.add(map);

                    } else {
                        map.put("article", article);
                        map.put("thumbs", "yes");
                        maps.add(map);
                    }

                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);


            }
        }




        return new Result(true, StatusCode.ERROR, "无记录！");
    }

    @RequestMapping(value = "/find_by_author_like", method = RequestMethod.POST)
    public Result findByAuthorLike(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size, String author) {
        Page<Article> articles = articleService.findByAuthorLike(author, page, size);
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (articles != null && articles.getSize()!=0) {
            List<Article> articleList = articles.getContent();

            if (token == null || "".equals(token)) {

                List<Map> maps = new ArrayList<Map>();

                for (Article article : articleList) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("article", article);
                    map.put("thumbs", "null");
                    maps.add(map);
                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);

            } else {
                String user_id = claims.getId();
                List<Map> maps = new ArrayList<Map>();
                for (Article article : articles) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    if (thumbsSerivlce.findThumbs(article.get_id(), user_id) == null) {
                        map.put("article", article);
                        map.put("thumbs", "no");
                        maps.add(map);

                    } else {
                        map.put("article", article);
                        map.put("thumbs", "yes");
                        maps.add(map);
                    }

                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);


            }
        }




        return new Result(true, StatusCode.ERROR, "无记录！");
    }

    @RequestMapping(value = "/find_by_type", method = RequestMethod.POST)
    public Result findByType(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size, String type) {
        Page<Article> articles = articleService.findByTypeAndPage(type, page, size);
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (articles != null && articles.getSize()!=0) {
            List<Article> articleList = articles.getContent();

            if (token == null || "".equals(token)) {

                List<Map> maps = new ArrayList<Map>();

                for (Article article : articleList) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("article", article);
                    map.put("thumbs", "null");
                    maps.add(map);
                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);

            } else {
                String user_id = claims.getId();
                List<Map> maps = new ArrayList<Map>();
                for (Article article : articles) {
                  String json=userClient.getUserById(article.getAuthor());
                  User user=JSON.parseObject(json,User.class);
                  article.setAuthorName(user.getUsername());
                    Map<String, Object> map = new HashMap<String, Object>();
                    if (thumbsSerivlce.findThumbs(article.get_id(), user_id) == null) {
                        map.put("article", article);
                        map.put("thumbs", "no");
                        maps.add(map);

                    } else {
                        map.put("article", article);
                        map.put("thumbs", "yes");
                        maps.add(map);
                    }

                }
                Map<String, Object> returnMap = new HashMap<String, Object>();
                returnMap.put("obj", maps);
                returnMap.put("total", articles.getTotalPages());
                returnMap.put("size", articles.getSize());
                returnMap.put("page", articles.getPageable());
                returnMap.put("articles", articles);
                return new Result(true, StatusCode.OK, "查询成功", returnMap);


            }
        }




        return new Result(true, StatusCode.ERROR, "无记录！");
    }

    @RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
    public Result getArticle(@PathVariable String id) {
        String token = (String) request.getAttribute("token");


        Map map = new HashMap();
        if (token == null || "".equals(token)) {


            Article article = articleService.findById(id);
            article.setCount(article.getCount() + 1);
          String json=userClient.getUserById(article.getAuthor());
          User user=JSON.parseObject(json,User.class);
          article.setAuthorName(user.getUsername());
            map.put("article", article);
            map.put("thumbs", "null");
            return new Result(true, StatusCode.OK, "浏览成功！", map);
        } else {
          Claims claims = jwtUtil.parseJWT(token);
            String user_id = claims.getId();
            Thumbs thumbs = thumbsSerivlce.findThumbs(id, user_id);

            if (thumbs == null) {
                Article article = articleService.findById(id);
              String json=userClient.getUserById(article.getAuthor());
              User user=JSON.parseObject(json,User.class);
              article.setAuthorName(user.getUsername());
              String type_id=article.getType();
                baseClient.record(user_id,type_id);
                article.setCount(article.getCount() + 1);
              System.out.println(article.getCount());
                articleService.addViewRecord(user_id,article.getCategory());
                articleService.update(article);

                map.put("article", article);
                map.put("thumbs", "no");
                return new Result(true, StatusCode.OK, "浏览成功！", map);
            } else {
                Article article = articleService.findById(id);
              String json=userClient.getUserById(article.getAuthor());
              User user=JSON.parseObject(json,User.class);
              article.setAuthorName(user.getUsername());
                baseClient.record(user_id,article.getType());
                article.setCount(article.getCount() + 1);
                articleService.addViewRecord(user_id,article.getCategory());
                articleService.update(article);
                map.put("article", article);
                map.put("thumbs", "yes");
                return new Result(true, StatusCode.OK, "浏览成功！", map);
            }

        }

    }
@RequestMapping(value = "/thumbs_up",method = RequestMethod.PUT)
public Result thumbs_up(@RequestBody Thumbs thumbs){

    String token = (String) request.getAttribute("token");
    Claims claims = jwtUtil.parseJWT(token);

    if (token == null || "".equals(token)) {
        return new Result(false, StatusCode.ACCESSERROR, "用户未登录！");
    }
    else {
        Thumbs findThumbs=thumbsSerivlce.findThumbs(thumbs.getArticle_id(),claims.getId());
        if(findThumbs!=null){
            return new Result(false, StatusCode.HAS, "重复点赞！");
        }
        thumbsSerivlce.addThumbs(thumbs);
        return new Result(true, StatusCode.OK, "点赞成功！");
    }


}

    @RequestMapping(value = "/thumbs_cancel",method = RequestMethod.DELETE)
    public Result thumbs_cancel(@RequestBody Thumbs thumbs){
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);

        if (token == null || "".equals(token)) {
            return new Result(false, StatusCode.ACCESSERROR, "用户未登录！");
        }
        else {
            Thumbs findThumbs=thumbsSerivlce.findThumbs(thumbs.getArticle_id(),claims.getId());
            if(findThumbs==null){
                return new Result(false, StatusCode.ERROR, "未点赞！");
            }
            thumbsSerivlce.deleteThumbs(thumbs.getArticle_id(),thumbs.getUser_id());
            return new Result(true, StatusCode.OK, "取消点赞成功！");
        }
    }

@RequestMapping(value = "/add_type",method = RequestMethod.PUT)
    public void add_type(@RequestParam String _id,@RequestParam String type_id){


        articleService.add_type(_id,type_id);

}

@RequestMapping(value = "/matching",method = RequestMethod.GET)

    public Result matching(){
    String token = (String) request.getAttribute("token");

    if(token== null || "".equals(token)) {
      System.out.println("空字符串");
      System.out.println("token++++++++++++++++:" + token);
    }
    if (token== null || "".equals(token)) {

        List<Article> articles=articleService.NotLogMatching();
        List<Map> maps=new ArrayList<Map>();

        for(Article article:articles){
          System.out.println(article.get_id());
          String json=userClient.getUserById(article.getAuthor());
          User user=JSON.parseObject(json,User.class);
          article.setAuthorName(user.getUsername());
            Map <String,Object> map=new HashMap<String,Object>();
            article.setTime(TimeDifference.count(article.getUploadTime()));
            map.put("article",article);
            map.put("thumbs",null);
            maps.add(map);
        }
        return new Result(true,StatusCode.OK,"查询成功",maps);
        //return new Result(false, StatusCode.ACCESSERROR, "用户未登录！");
    }

    else{
      Claims claims = jwtUtil.parseJWT(token);
      String role = (String) claims.get("roles");
      if (!role.equals("ROLE_USER")){

        List<Article> articles=articleService.NotLogMatching();
        List<Map> maps=new ArrayList<Map>();

        for(Article article:articles){
          System.out.println(article.get_id());
          String json=userClient.getUserById(article.getAuthor());
          User user=JSON.parseObject(json,User.class);
          article.setAuthorName(user.getUsername());
          Map <String,Object> map=new HashMap<String,Object>();
          article.setTime(TimeDifference.count(article.getUploadTime()));
          map.put("article",article);
          map.put("thumbs",null);
          maps.add(map);
        }
        return new Result(true,StatusCode.OK,"查询成功",maps);
        //return new Result(false, StatusCode.ACCESSERROR, "用户未登录！");
      }


      String user_id=claims.getId();
        List<String> jsons=baseClient.getList(user_id);
      System.out.println(jsons);
        List<Article> articles=articleService.userMatching(jsons,user_id);
        List<Map> maps=new ArrayList<Map>();

        for(Article article:articles){
          String json=userClient.getUserById(article.getAuthor());
          User user=JSON.parseObject(json,User.class);
          article.setAuthorName(user.getUsername());
          article.setTime(TimeDifference.count(article.getUploadTime()));
            Map <String,Object> map=new HashMap<String,Object>();
            if(thumbsSerivlce.findThumbs(article.get_id(),user_id)==null){
                map.put("article",article);
                map.put("thumbs","no");
                maps.add(map);

            }else {
                map.put("article",article);
                map.put("thumbs","yes");
                maps.add(map);
            }

        }
        return new Result(true,StatusCode.OK,"查询成功",maps);


    }
}

  @RequestMapping(value = "/search_by_title/{page}",method = RequestMethod.GET)
  public Result search_title(@RequestParam String title ,@PathVariable int page){


    Page<Article> pages=articleService.findByTitle(title,page,5);
    for(Article a:pages.getContent()){

      a.setTime(TimeDifference.count(a.getUploadTime()));
    }
    return new Result(true, StatusCode.OK, "查询成功",pages);
  }
  @RequestMapping(value = "/search_by_label/{page}",method = RequestMethod.GET)
  public Result search_label(@RequestBody Article article, @PathVariable int page){


    Page<Article> pages=articleService.findByLabelAndPage(article.getLabel(),page,10);
    for(Article a:pages.getContent()){

      a.setTime(TimeDifference.count(a.getUploadTime()));
    }
    return new Result(true, StatusCode.OK, "查询成功",pages);
  }
  @RequestMapping(value = "/search_by_author_like/{page}",method = RequestMethod.GET)
  public Result search_author_like(@RequestBody Article article ,@PathVariable int page){
    Page<Article> pages=articleService.findByAuthorLike(article.getAuthor(),page,5);
    for(Article a:pages.getContent()){

      a.setTime(TimeDifference.count(a.getUploadTime()));
    }
    return new Result(true, StatusCode.OK, "查询成功",pages);
  }
  @RequestMapping(value = "/search_by_author/{page}/{author}",method = RequestMethod.GET)
  public Result search_author(@PathVariable String author ,@PathVariable int page){
    Page<Article> pages=articleService.findByAuthorAndPage(author,page,5);
    for(Article a:pages.getContent()){

      a.setTime(TimeDifference.count(a.getUploadTime()));
    }
    return new Result(true, StatusCode.OK, "查询成功",pages);
  }
  @RequestMapping(value = "/search_by_category/{page}",method = RequestMethod.GET)
  public Result search_category(@RequestBody Article article ,@PathVariable int page){
    Page<Article> pages=articleService.findByCategoryAndPage(article.getCategory(),page,10);
    for(Article a:pages.getContent()){

      a.setTime(TimeDifference.count(a.getUploadTime()));
    }
    return new Result(true, StatusCode.OK, "查询成功",pages);
  }
  @RequestMapping(value = "/search_by_type/{page}",method = RequestMethod.GET)
  public Result search_type(@RequestBody Article article ,@PathVariable int page){
    Page<Article> pages=articleService.findByTypeAndPage(article.getType(),page,10);
    for(Article a:pages.getContent()){

      a.setTime(TimeDifference.count(a.getUploadTime()));
    }
    return new Result(true, StatusCode.OK, "查询成功",pages);
  }
}
